package com.tools.middle.elasticsearch;

import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
import co.elastic.clients.elasticsearch.core.search.HighlightField;
import com.tools.common.container.OwnPairs;
import com.tools.common.object.Note;
import com.tools.common.thread.Timeunit;

import java.util.Map;

/**
 * 普通的 ?q=xxx 查询。
 * 在多条件查询时不起作用，要使用 StringSearch 类替代它
 * */
@Note("通的 ?q=xxx 查询。" +
        "在多条件查询时不起作用，要使用 StringSearch 类替代它")
public final class QSearch extends Search {

    @Note("要查询的关键字")
    private String q;

    /* **********************************************************************************
     *
     *          构造器
     *
     * *********************************************************************************
     * */

    public QSearch(String q, String indicesName) {
        super(indicesName);
        this.setQ(q);
    }

    public QSearch(String q, String... indicesNames) {
        super(indicesNames);
        this.setQ(q);
    }

    public QSearch(String q, Iterable<String> indicesNames) {
        super(indicesNames);
        this.setQ(q);
    }

    public static QSearch of(String q, String indicesName) {
        return new QSearch(q, indicesName);
    }

    public static QSearch of(String q, String... indicesNames) {
        return new QSearch(q, indicesNames);
    }

    public static QSearch of(String q, Iterable<String> indicesNames) {
        return new QSearch(q, indicesNames);
    }

    /* **********************************************************************************
     *
     *          Getter / Setter
     *
     * *********************************************************************************
     * */

    public String getQ() {
        return q;
    }

    public void setQ(String q) {
        if(q == null || q.isEmpty()) throw new IllegalArgumentException("要查询的内容不能为空");
        this.q = q;
    }

    /* **********************************************************************************
     *
     *          链式方法
     *
     * *********************************************************************************
     * */

    @Override
    public QSearch indicesNames(String indicesName) {
        super.setIndicesNames(indicesName);
        return this;
    }

    @Override
    public QSearch indicesNames(String... indicesNames) {
        super.setIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch indicesNames(Iterable<String> indicesNames) {
        super.setIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch timeout(String timeout) {
        super.setTimeout(timeout);
        return this;
    }

    @Override
    public QSearch timeout(int timeout, Timeunit timeunit) {
        super.setTimeout(timeout, timeunit);
        return this;
    }

    @Override
    public QSearch from(int from) {
        super.setFrom(from);
        return this;
    }

    @Override
    public QSearch size(int size) {
        super.setSize(size);
        return this;
    }

    public QSearch q(String q) {
        this.setQ(q);
        return this;
    }

    @Override
    public QSearch analyzer(String analyzer) {
        super.setAnalyzer(analyzer);
        return this;
    }

    @Override
    public QSearch sorts(String field, SortOrder order) {
        super.sorts(field, order);
        return this;
    }

    @Override
    public QSearch sorts(Map<String, SortOrder> fieldAndOrders) {
        super.sorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch sorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.sorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch includes(String includeField) {
        super.includes(includeField);
        return this;
    }

    @Override
    public QSearch includes(String... includeFields) {
        super.includes(includeFields);
        return this;
    }

    @Override
    public QSearch includes(Iterable<String> includeFields) {
        super.includes(includeFields);
        return this;
    }

    @Override
    public QSearch excludes(String excludeField) {
        super.excludes(excludeField);
        return this;
    }

    @Override
    public QSearch excludes(String... excludeFields) {
        super.excludes(excludeFields);
        return this;
    }

    @Override
    public QSearch excludes(Iterable<String> excludeFields) {
        super.excludes(excludeFields);
        return this;
    }

    @Override
    public QSearch aggregations(String field, Aggregation agg) {
        super.aggregations(field, agg);
        return this;
    }

    @Override
    public QSearch aggregations(Map<String, Aggregation> aggregations) {
        super.aggregations(aggregations);
        return this;
    }

    @Override
    public QSearch aggregations(OwnPairs<String, Aggregation> aggregations) {
        super.aggregations(aggregations);
        return this;
    }

    @Override
    public QSearch highlights(String field, HighlightField highlightField) {
        super.highlights(field, highlightField);
        return this;
    }

    @Override
    public QSearch highlights(Map<String, HighlightField> highlights) {
        super.highlights(highlights);
        return this;
    }

    @Override
    public QSearch highlights(OwnPairs<String, HighlightField> highlights) {
        super.highlights(highlights);
        return this;
    }

    /* **********************************************************************************
     *
     *          自定义方法
     *
     * *********************************************************************************
     * */

    @Override
    public QSearch addIndicesName(String indicesName) {
        super.addIndicesName(indicesName);
        return this;
    }

    @Override
    public QSearch addIndicesNames(String... indicesNames) {
        super.addIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch addIndicesNames(Iterable<String> indicesNames) {
        super.addIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch modifyIndicesName(int index, String indicesName) {
        super.modifyIndicesName(index, indicesName);
        return this;
    }

    @Override
    public QSearch removeIndicesName(String indicesName) {
        super.removeIndicesName(indicesName);
        return this;
    }

    @Override
    public QSearch removeIndicesName(int index) {
        super.removeIndicesName(index);
        return this;
    }

    @Override
    public QSearch removeIndicesNames(String... indicesNames) {
        super.removeIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch removeIndicesNames(Iterable<String> indicesNames) {
        super.removeIndicesNames(indicesNames);
        return this;
    }

    @Override
    public QSearch addSort(String field, SortOrder order) {
        super.addSort(field, order);
        return this;
    }

    @Override
    public QSearch addSorts(Map<String, SortOrder> fieldAndOrders) {
        super.addSorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch addSorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.addSorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch modifySort(int index, String field, SortOrder order) {
        super.modifySort(index, field, order);
        return this;
    }

    @Override
    public QSearch clearSorts() {
        super.clearSorts();
        return this;
    }

    @Override
    public QSearch removeSort(String field, SortOrder order) {
        super.removeSort(field, order);
        return this;
    }

    @Override
    public QSearch removeSort(int index) {
        super.removeSort(index);
        return this;
    }

    @Override
    public QSearch removeSorts(Map<String, SortOrder> fieldAndOrders) {
        super.removeSorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch removeSorts(OwnPairs<String, SortOrder> fieldAndOrders) {
        super.removeSorts(fieldAndOrders);
        return this;
    }

    @Override
    public QSearch addInclude(String field) {
        super.addInclude(field);
        return this;
    }

    @Override
    public QSearch addIncludes(String... fields) {
        super.addIncludes(fields);
        return this;
    }

    @Override
    public QSearch addIncludes(Iterable<String> fields) {
        super.addIncludes(fields);
        return this;
    }

    @Override
    public QSearch modifyInclude(int index, String field) {
        super.modifyInclude(index, field);
        return this;
    }

    @Override
    public QSearch clearIncludes() {
        super.clearIncludes();
        return this;
    }

    @Override
    public QSearch removeInclude(String field) {
        super.removeInclude(field);
        return this;
    }

    @Override
    public QSearch removeInclude(int index) {
        super.removeInclude(index);
        return this;
    }

    @Override
    public QSearch removeIncludes(String... fields) {
        super.removeIncludes(fields);
        return this;
    }

    @Override
    public QSearch removeIncludes(Iterable<String> fields) {
        super.removeIncludes(fields);
        return this;
    }

    @Override
    public QSearch addExclude(String field) {
        super.addExclude(field);
        return this;
    }

    @Override
    public QSearch addExcludes(String... fields) {
        super.addExcludes(fields);
        return this;
    }

    @Override
    public QSearch addExcludes(Iterable<String> fields) {
        super.addExcludes(fields);
        return this;
    }

    @Override
    public QSearch modifyExclude(int index, String field) {
        super.modifyExclude(index, field);
        return this;
    }

    @Override
    public QSearch clearExcludes() {
        super.clearExcludes();
        return this;
    }

    @Override
    public QSearch removeExclude(String field) {
        super.removeExclude(field);
        return this;
    }

    @Override
    public QSearch removeExclude(int index) {
        super.removeExclude(index);
        return this;
    }

    @Override
    public QSearch removeExcludes(String... fields) {
        super.removeExcludes(fields);
        return this;
    }

    @Override
    public QSearch removeExcludes(Iterable<String> fields) {
        super.removeExcludes(fields);
        return this;
    }

    @Override
    public QSearch addAgg(String field, Aggregation agg) {
        super.addAgg(field, agg);
        return this;
    }

    @Override
    public QSearch addAggs(Map<String, Aggregation> aggs) {
        super.addAggs(aggs);
        return this;
    }

    @Override
    public QSearch addAggs(OwnPairs<String, Aggregation> aggs) {
        super.addAggs(aggs);
        return this;
    }

    @Override
    public QSearch clearAggs() {
        super.clearAggs();
        return this;
    }

    @Override
    public QSearch removeAgg(String field) {
        super.removeAgg(field);
        return this;
    }

    @Override
    public QSearch removeAgg(String... fields) {
        super.removeAgg(fields);
        return this;
    }

    @Override
    public QSearch removeAgg(Iterable<String> fields) {
        super.removeAgg(fields);
        return this;
    }

    @Override
    public QSearch addHighlight(String field, HighlightField highlightField) {
        super.addHighlight(field, highlightField);
        return this;
    }

    @Override
    public QSearch addHighlights(Map<String, HighlightField> highlights) {
        super.addHighlights(highlights);
        return this;
    }

    @Override
    public QSearch addHighlights(OwnPairs<String, HighlightField> highlights) {
        super.addHighlights(highlights);
        return this;
    }

    @Override
    public QSearch clearHighlight() {
        super.clearHighlight();
        return this;
    }

    @Override
    public QSearch removeHighlight(String field) {
        super.removeHighlight(field);;
        return this;
    }

    @Override
    public QSearch removeHighlights(String... fields) {
        super.removeHighlights(fields);
        return this;
    }

    @Override
    public QSearch removeHighlights(Iterable<String> fields) {
        super.removeHighlights(fields);
        return this;
    }

}
